/*
 * CS_REQ_COSTUME_INFO.cpp
 *
 *  Created on: 2013. 10. 22.
 *      Author: mega@gamevil.com
 */

#include "../../Command.h"

#include "../../User.h"
#include "../../NLogic/Space.h"
#include "../../NLogic/Equip.h"
#include "../../NLogic/Party.h"

namespace ProjectZ { namespace NCommand {

void Command::CS_REQ_COSTUME_INFO(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;

	DEBUGLOG("##### Costuminfo userseq=%d, Latency=%d", pUser->GetUserSeq(), pUser->GetLastLatency());

	int userSeq = 0;

	*pPacket >> userSeq;

	NLogic::Space * pSpace	= pUser->GetSpace();

	if (pSpace == NULL)
	{
		// TODO : Error!!
		DEBUGLOG("CS_REQ_COSTUME_INFO : pSpace is NULL!!!");
		return;
	}

	User * pOppUser = pSpace->FindUser(userSeq);

	if (pOppUser == NULL)
	{
		// TODO : Error!!
		DEBUGLOG("CS_REQ_COSTUME_INFO : pOppUser is NULL!!!");
		return;
	}

	NLogic::Equip * pEquip = pOppUser->GetEquip();
	if (NULL == pEquip)
	{
		DEBUGLOG("CS_REQ_COSTUME_INFO : pEquip is NULL!!!");
		return;
	}

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();

	*pAck << userSeq;

	// 아바타를 장착한 경우
	if (true == pEquip->IsExistItem(ITEM_EQUIP_POS_AVARTAR))
	{
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_AVARTAR) + 100);
	}
	else
	{
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_HELMET));
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_ARMOR));
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_WEAPON));
		*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_WEAPON));
	}

	*pAck << static_cast<uint8_t>(0);
	*pAck << static_cast<uint8_t>(pEquip->GetEquipItemIconIndex(ITEM_EQUIP_POS_VEHICLE));

	pAck->MakePacket(CMD_SC_REQ_COSTUME_INFO);

	pUser->Send(pAck);

//	// PVP 대전의 경우 타이머 설정
//	if (pSpace->GetData()._spaceType == NLogic::Space::SpaceType::PVP_USER)
//	{
//		pSpace->GetParty()->SetState(NLogic::Party::State::PVP_ENTERROOM_WAIT);
//	}
}


} /*NCommand*/ } /*ProjectZ*/


